<template>
  <div class="scale-box" :id="dynamicIdName()">
    <div
      class="hall-situation-box animate__animated"
      style="width: 460px; height: 578px"
      :id="dynamicChildName()"
    >
      <h1 class="h1_title">
        <span>大厅概况</span>
      </h1>
      <div class="light">
        <div class="light-item">
          <p>入驻部门</p>
          <p class="light-num">
            <span><em>120</em>个</span>
          </p>
        </div>
        <div class="light-item">
          <p>入驻事项</p>
          <p class="light-num">
            <span><em>120</em>个</span>
          </p>
        </div>
        <div class="light-item">
          <p>入驻人员</p>
          <p class="light-num">
            <span><em>120</em>个</span>
          </p>
        </div>
      </div>
      <!-- 窗口运行 -->
      <h2 class="h2_title"><span>窗口运行</span></h2>
      <div class="window-num">
        <span class="window-num-text">开设窗口</span>
        <ScrollNumber :value="windownum" class="stock-price"></ScrollNumber
        ><span class="unit">个</span>
      </div>
      <div class="card">
        <div class="card-item">
          <p>大厅人员出入数量</p>
          <p class="light-num">
            <span><em>120</em>个</span>
          </p>
        </div>
        <div class="card-item">
          <p>历史办件等待时长</p>
          <p class="light-num">
            <span><em>120</em>min</span>
          </p>
        </div>
      </div>
      <div class="sp-wrap">
        <div class="sp-item">
          <p>审批数量</p>
          <p>
            <span><em>120</em>件</span>
          </p>
        </div>
        <div class="sp-item">
          <p>审批时长</p>
          <p>
            <span><em>120</em>min</span>
          </p>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import axios from "axios";
import ScrollNumber from "./ScrollNumber.vue";
//引入封装方法
import encapsulation from "../../utils/aircimGird";
export default {
  name: "HallSituaction",
  grid_specification: "aircim_grid_1x1",
  //混入封装方法
  mixins: [encapsulation],
  components: {
    ScrollNumber,
  },
  data() {
    return {
      windownum: 0,
      resizeObserver: null,
      //动态Id
      timestamp: null,
    };
  },
  mounted() {
    this.windownum = 0;
    setTimeout(() => {
      this.windownum = 88.888;
    }, 1000);
    this.getNormalData();
    this.timestamp = new Date().getTime();
    this.$nextTick(() => {
      // 监听盒子变化
      this.listenChangeFn();
    });
  },
  methods: {
    initGrid() {},
    refreshData() {
      this.getNormalData();
    },
    getNormalData() {
      axios
        .post("http://192.168.250.14/DCockpit/rest/cockpitApi/getNormDatas", {
          normParams: [
            {
              dim5: "",
              kylinCondition: "",
              dim4: "",
              dim3: "",
              dim2: "",
              dim1: "",
              start: "",
              normGuid: "a83c1515-7e43-45e7-9642-bde04c3febee",
              end: "",
              singleValueIsArrary: "",
              kylinParams: "",
              fieldList: "",
            },
          ],
          userGuid: "4813746c-1141-4ddf-8c00-5ebf5e21aeb9",
        })
        .then((res) => {
          console.log(res);
        });
    },
    refreshConfig(val) {},
    //监听外部盒子的大小 然后对数据井行缩放
    scaleFn() {
      const parentBox = document.getElementById(`dynamic-${this.timestamp}`);
      const childBox = document.getElementById(
        `dynamicChild-${this.timestamp}`
      );
      const parentWidth = parentBox.offsetWidth;
      const parentHeight = parentBox.offsetHeight;
      const childWidth = childBox.offsetWidth;
      const childHeight = childBox.offsetHeight;
      let scaleX, scaleY;
      if (parentWidth < childWidth || parentHeight < childHeight) {
        const scaleBasedOnWidth = parentWidth / childWidth;
        const scaleBasedOnHeight = parentHeight / childHeight;
        scaleX = scaleBasedOnWidth;
        scaleY = scaleBasedOnHeight;
      } else {
        scaleX = parentWidth / childWidth;
        scaleY = parentHeight / childHeight;
      }
      childBox.style.transform = `scale(${scaleX}, ${scaleY})`;
    },
    // 监听盒子变化
    listenChangeFn() {
      let that = this;
      const element = document.getElementById(`dynamic-${this.timestamp}`);
      // console.log(element, "element");
      if (element) {
        new ResizeObserver(() => {
          // 处理元素大小变化的逻辑
          that.scaleFn();
        }).observe(element);
      }
    },
    // 绑定动画样式 animate__flash
    bindAnimationFn(animateName) {
      if (animateName != null) {
        this.dynamicClassName = animateName;
      }
    },
    //定义唯一ID名
    dynamicIdName() {
      return `dynamic-${this.timestamp}`;
    },
    //定义唯一ID名
    dynamicChildName() {
      return `dynamicChild-${this.timestamp}`;
    },
  },
  // 销毁监听
  beforeDestroy() {
    // 组件销毁前停止监听
    if (this.resizeObserver) {
      this.resizeObserver.disconnect();
    }
    if (this.requestTime != null) {
      clearInterval(this.requestTime);
    }
  },
};
</script>
<style lang="scss" scoped>
@import "../../static/assets/common.scss";
</style>
<style lang="scss" scoped>
.scale-box {
  width: 100%;
  height: 100%;
}

.hall-situation-box {
  width: 460px;
  height: 578px;
  padding: 0 20px;
  box-sizing: border-box;
  overflow: hidden;
  background-image: url(../../../thumbnail/backImg/new-border-green.png);
  background-size: 100% 100%;
  background-repeat: no-repeat;
  color: #fff;
  transform-origin: left top;

  .grid-charts {
    width: 100%;
    height: 100%;
  }
}

* {
  box-sizing: border-box;
}

// 大厅概况
.light {
  margin: 17px 0 23px 0;
  display: flex;
  justify-content: space-between;

  .light-item {
    position: relative;
    width: 33.33%;
    height: 105px;
    text-align: center;

    &::after {
      content: "";
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      z-index: -1;
      background: url(../../static/assets/HallSituation/hall_light.png)
        no-repeat center bottom;
      animation: fade-with-delay 2s ease-out infinite;
    }

    p:first-of-type {
      font-size: 16px;
      line-height: 24px;
    }

    p:last-of-type {
      margin: 6px 0 0 0;
      color: #96bee0;
      font-size: 14px;
      line-height: 24px;

      em {
        color: #0ff;
        font-family: D-DIN;
        font-size: 24px;
        font-style: normal;
      }
    }
  }
}

// 窗口运行
.window-num {
  margin-bottom: 23px;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 76px;
  background: url(../../static/assets/HallSituation/window_mocule_bg.png)
    no-repeat center center;
  background-size: 100% 100%;

  .window-num-text {
    min-width: 106px;
    font-size: 16px;
    font-weight: 700;
  }

  .unit {
    color: rgba(150, 190, 224, 0.8);
    margin-left: 16px;
    font-size: 14px;
  }
}

.card {
  display: flex;
  height: 91px;
  justify-content: space-between;

  .card-item {
    padding-top: 17px;
    text-align: center;
    width: calc(50% - 15px);
    height: 100%;
    background: url(../../static/assets/HallSituation/card-bg.png) no-repeat
      center center;
    background-size: 100% 100%;

    p:first-of-type {
      font-size: 16px;
    }

    p:last-of-type {
      margin-top: 6px;
      line-height: 26px;
      color: #96bee0;
      font-size: 14px;

      em {
        padding-right: 3px;
        color: #0ff;
        font-family: D-DIN;
        font-size: 24px;
      }
    }
  }
}

.sp-wrap {
  margin-top: 34px;
  padding-left: 105px;
  height: 98px;
  display: flex;
  align-items: center;
  background: rgba(32, 113, 164, 0.14)
    url(../../static/assets/HallSituation/icon.png) no-repeat 5px center;
  background-size: 118px 92px;
  font-size: 16px;

  .sp-item {
    width: 50%;
    position: relative;
    display: inline-flex;
    flex-direction: column;
    align-items: center;

    &:last-of-type:after {
      content: "";
      position: absolute;
      height: 58px;
      width: 2px;
      background-image: linear-gradient(
        180deg,
        rgba(0, 109, 143, 0.2),
        rgba(0, 109, 143, 0.8),
        rgba(0, 109, 143, 0.2)
      );
      left: 0;
      top: 50%;
      transform: translateY(-50%);
    }

    p:first-of-type {
      padding-left: 28px;
      background: url(../../static/assets/HallSituation/arrow.png) no-repeat
        left center;
    }

    p:last-of-type {
      margin-top: 10px;
      padding-left: 28px;
      color: #96bee0;
      font-size: 14px;

      em {
        color: #0ff;
        padding-right: 2px;
        font-family: D-DIN;
        font-size: 24px;
      }
    }
  }
}

@keyframes fade-with-delay {
  0% {
    opacity: 0.7;
  }

  30% {
    opacity: 1;
  }

  /* 快速完成淡入 */
  70% {
    opacity: 1;
  }

  /* 保持可见1秒 */
  100% {
    opacity: 0.7;
  }
}
</style>
